// main.qml - 时钟应用
import QtQuick 2.15
import QtQuick.Window 2.15

Window {
    width: 800
    height: 1200
    visible: true
    title: "Qt 时钟 for 鸿蒙"

    // 渐变背景
    Rectangle {
        anchors.fill: parent
        gradient: Gradient {
            GradientStop { position: 0.0; color: "#0F2027" }
            GradientStop { position: 0.5; color: "#203A43" }
            GradientStop { position: 1.0; color: "#2C5364" }
        }

        Column {
            anchors.centerIn: parent
            spacing: 40

            // 数字时钟显示
            Text {
                id: timeDisplay
                text: Qt.formatTime(new Date(), "hh:mm:ss")
                font.pixelSize: 120
                font.bold: true
                font.family: "Arial"
                color: "#FFFFFF"
                anchors.horizontalCenter: parent.horizontalCenter
                
                // 发光效果
                style: Text.Outline
                styleColor: "#00D4FF"
            }

            // 日期显示
            Column {
                spacing: 10
                anchors.horizontalCenter: parent.horizontalCenter

                Text {
                    id: dateDisplay
                    text: Qt.formatDate(new Date(), "yyyy年MM月dd日")
                    font.pixelSize: 36
                    color: "#B0E0E6"
                    anchors.horizontalCenter: parent.horizontalCenter
                }

                Text {
                    id: weekDisplay
                    text: dateHelper.getWeekDay()  // 使用 C++ 实现
                    font.pixelSize: 28
                    color: "#87CEEB"
                    anchors.horizontalCenter: parent.horizontalCenter
                }
            }

            // 装饰性分隔线
            Rectangle {
                width: 300
                height: 2
                color: "#00D4FF"
                radius: 1
                anchors.horizontalCenter: parent.horizontalCenter
                opacity: 0.6
            }

            // 品牌信息
            Text {
                text: "坚果派 × Qt for 鸿蒙"
                font.pixelSize: 24
                color: "#FFFFFF"
                opacity: 0.7
                anchors.horizontalCenter: parent.horizontalCenter
            }
        }

        // 定时器 - 每秒更新
        Timer {
            interval: 1000  // 1秒
            running: true
            repeat: true
            onTriggered: {
                var currentTime = new Date()
                timeDisplay.text = Qt.formatTime(currentTime, "hh:mm:ss")
                dateDisplay.text = Qt.formatDate(currentTime, "yyyy年MM月dd日")
                weekDisplay.text = dateHelper.getWeekDay()  // 使用 C++ 实现
            }
        }

        // 点击切换12/24小时制
        property bool is24Hour: true

        MouseArea {
            anchors.fill: parent
            onClicked: {
                parent.is24Hour = !parent.is24Hour
                var currentTime = new Date()
                if (parent.is24Hour) {
                    timeDisplay.text = Qt.formatTime(currentTime, "hh:mm:ss")
                } else {
                    timeDisplay.text = Qt.formatTime(currentTime, "h:mm:ss AP")
                }
            }
        }

        // 原来的 JavaScript getWeekDay() 函数已移至 C++ DateHelper 类
        // 现在通过 dateHelper.getWeekDay() 调用 C++ 实现
    }
}